using System;
using System.Collections.Generic;
using dbvc.data;
using dbvc.Queries;

namespace dbvc.context.User
{
    public static partial class User
    {
        public static void delete(this db_user self)
        {
            GenericQuery<db_user>.Delete(self);
        }
    }

    public class DeleteUser
    {
        private readonly db_user user;
        private readonly IEnumerable<db_user> users;
        private db_activity activity;

        public DeleteUser(db_user _principal, IEnumerable<db_user> _users)
        {
            user = _principal;
            users = _users;
        }

        public void Execute()
        {
            foreach (db_user usr in users)
            {
                if (usr.name != "root")
                {
                    activity = new
                        db_activity
                                   {
                                       action = "delete user",
                                       datestamp = DateTime.Now,
                                       userstamp = user.name
                                   };

                    usr.delete();
                    activity.save();
                }
            }
        }
    }
}